package com.nodecollege.cloud.controller.admin;

import com.nodecollege.cloud.common.annotation.ApiAnnotation;
import com.nodecollege.cloud.common.constants.NCConstants;
import com.nodecollege.cloud.common.model.NCResult;
import com.nodecollege.cloud.common.model.QueryVO;
import com.nodecollege.cloud.common.model.po.UpmsAdmin;
import com.nodecollege.cloud.common.model.vo.LoginVO;
import com.nodecollege.cloud.common.annotation.AdminLoginAnnotation;
import com.nodecollege.cloud.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author LC
 * @date 2019/11/27 20:55
 */
@RestController
@AdminLoginAnnotation
@RequestMapping("/admin/admin")
public class AdminController {

    @Autowired
    private AdminService adminService;

    /**
     * 获取管理员列表
     *
     * @param queryVO
     */
    @ApiAnnotation(modularName = "管理员管理", description = "获取管理员列表")
    @PostMapping("/getAdminList")
    public NCResult<UpmsAdmin> getAdminList(@RequestBody QueryVO<UpmsAdmin> queryVO) {
        //  登录认证
        return adminService.getAdminList(queryVO);
    }

    /**
     * 新增管理员信息
     *
     * @param loginVO
     * @return
     */
    @ApiAnnotation(modularName = "管理员管理", description = "新增管理员信息")
    @PostMapping("/addAdmin")
    public NCResult addAdmin(@RequestBody LoginVO loginVO) {
        loginVO.setSource(NCConstants.INT_1);
        adminService.addAdmin(loginVO);
        return NCResult.ok();
    }

    /**
     * 更新用户信息
     *
     * @param admin
     */
    @ApiAnnotation(modularName = "管理员管理", description = "更新管理员")
    @PostMapping("/updateAdmin")
    public NCResult updateAdmin(@RequestBody UpmsAdmin admin) {
        adminService.updateAdmin(admin);
        return NCResult.ok();
    }

    /**
     * 删除管理员
     * @param admin
     */
    @ApiAnnotation(modularName = "管理员管理", description = "删除管理员")
    @PostMapping("/delAdmin")
    public NCResult delAdmin(@RequestBody UpmsAdmin admin){
        adminService.delAdmin(admin.getAdminId());
        return NCResult.ok();
    }

    @ApiAnnotation(modularName = "管理员管理", description = "锁定/解锁管理员")
    @PostMapping("/lockAdmin")
    public NCResult lockAdmin(@RequestBody UpmsAdmin admin){
        adminService.lockAdmin(admin);
        return NCResult.ok();
    }

    @ApiAnnotation(modularName = "管理员管理", description = "重置管理员密码")
    @PostMapping("/resetPwd")
    public NCResult resetPwd(@RequestBody UpmsAdmin admin){
        adminService.resetPwd(admin);
        return NCResult.ok();
    }
}
